package com.edu.exam.enums.user;

import com.edu.exam.enums.core.StatusEnum;

/**
 * 用户状态枚举
 */
public enum UserStatus implements StatusEnum {

    ACTIVE("ACTIVE", "正常"),
    INACTIVE("INACTIVE", "未激活"),
    LOCKED("LOCKED", "锁定"),
    DELETED("DELETED", "已删除");

    private final String code;
    private final String description;

    UserStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     */
    public static UserStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return INACTIVE; // 默认未激活
        }

        for (UserStatus value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown user status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     */
    public static UserStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return INACTIVE; // 默认未激活
        }

        for (UserStatus value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown user status description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}